﻿using System;
using System.Collections.Generic;
using Godot;

namespace kemocard.Scripts.Buff;

public static class BuffFactory
{
    private static readonly Dictionary<string, Type> BuffTypeDict = new()
    {
        { "1", typeof(B1) },
        { "6", typeof(B6) },
        { "7", typeof(B7) },
        { "9", typeof(B9) },
        { "10", typeof(B10) },
        { "13", typeof(B13) },
        { "14", typeof(B14) },
        { "15", typeof(B15) },
        { "17", typeof(B17) },
        { "19E", typeof(B19E) },
        { "19T", typeof(B19T) },
        { "21", typeof(B21) },
        { "22", typeof(B22) },
        { "23", typeof(B23) },
        { "24", typeof(B24) },
        { "25", typeof(B25) },
        { "29", typeof(B29) },
        { "30", typeof(B30) },
        { "34", typeof(B34) },
        { "35", typeof(B35) },
        { "36", typeof(B36) },
        { "37", typeof(B37) },
        { "38", typeof(B38) },
        { "39", typeof(B39) },
        { "40", typeof(B40) },
        { "44", typeof(B44) },
        { "45", typeof(B45) },
        { "46", typeof(B46) },
        { "47", typeof(B47) },
        { "48", typeof(B48) },
        { "49", typeof(B49) },
        { "51", typeof(B51) },
        { "52", typeof(B52) },
        { "HAMSTER_SPA", typeof(HamsterSpa) },
        { "HAMSTER_SPD", typeof(HamsterSpd) },
        { "BAT_EARTH_GUARD", typeof(BatEarthGuard) },
        { "BAT_EATH_BLOCKER", typeof(BatEarthBlocker) },
        { "BAT_EARTH_SUPPORT", typeof(BatEarthSupport) },
        { "ACID_WORM_ATTACKER", typeof(AcidWormAttacker) },
        { "ACID_WORM_DEFENDER_E", typeof(AcidWormDefenderE) },
        { "ACID_WORM_DEFENDER_T", typeof(AcidWormDefenderT) },
        { "ACID_WORM_BLOCKER_E", typeof(AcidWormBlockerE) },
        { "ACID_WORM_BLOCKER_T", typeof(AcidWormBlockerT) },
        { "ROVER_TYPHOON_SUPPORT", typeof(RoverTyphoonSupport) },
        { "ROVER_TYPHOON_GUARD", typeof(RoverTyphoonGuard) },
        { "ROVER_TYPHOON_BLOCKER", typeof(RoverTyphoonBlocker) },
        { "SN_STAR_GUARD", typeof(SnStarGuard) },
        { "SN_STAR_SUPPORT", typeof(SnStarSupport) },
        { "FES_ZELLER_GUARD", typeof(FesZellerGuard) },
        { "FES_ZELLER_BLOCKER", typeof(FesZellerBlocker) },
        { "SN_SETH_GUARD", typeof(SnSethGuard) },
        { "SN_SETH_BLOCKER", typeof(SnSethBlocker) },
        { "SN_SETH_SUPPORT", typeof(SnSethSupport) },
        { "ADD_MAX_HEALTH_10000", typeof(AddMaxHealth10000) },
        { "ADD_PATTACK_2000", typeof(AddPAttack2000) },
        { "ACID_WORM_MDDOWN", typeof(AcidWormMdDown) },
        { "TAUNT1", typeof(Taunt1) },
        { "53", typeof(B53) },
        { "55", typeof(B55) },
        { "56", typeof(B56) },
        { "57", typeof(B57) },
        { "58", typeof(B58) },
        { "59", typeof(B59) },
        { "61", typeof(B61) },
        { "62", typeof(B62) },
        { "63", typeof(B63) },
        { "64", typeof(B64) },
        { "66", typeof(B66) },
        { "67", typeof(B67) },
        { "SLIME_EARTH_GUARD", typeof(SlimeEarthGuard) },
        { "SLIME_EARTH_BLOCKER", typeof(SlimeEarthBlocker) },
        { "SWAN_GUARD", typeof(SwanGuard) },
        { "SWAN_SUPPORT", typeof(SwanSupport) },
        { "CHALUX_SKILL_BUFF", typeof(ChaluxSkillBuff) },
        { "MERLIN_SKILL_BUFF", typeof(MerlinSkillBuff) },
        { "FORGE_SKILL_BUFF", typeof(ForgeSkillBuff) },
        { "COLLIN_SKILL_BUFF", typeof(CollinSkillBuff) },
        { "SETH_SKILL_BUFF", typeof(SethSkillBuff) },
        { "RAINS_SKILL_BUFF", typeof(RainsSkillBuff) },
        { "CARTER_SKILL_BUFF", typeof(CarterSkillDebuff) },
        { "ZELLER_SKILL_BUFF", typeof(ZellerSkillBuff) },
        { "SANTOS_SKILL_BUFF", typeof(SantosSkillBuff) },
        { "TYPHOON_SKILL_BUFF", typeof(TyphoonSkillBuff) },
        { "LIZ_EARTH_ATTACKER", typeof(LizEarthAttacker) },
        { "LIZ_EARTH_GUARD", typeof(LizEarthGuard) },
        { "SCI_SANTOS_A_E", typeof(SciSantosAe) },
        { "SCI_SANTOS_A_T", typeof(SciSantosAt) },
        { "SCI_SANTOS_G", typeof(SciSantosG) },
        { "SS_RAINS_G", typeof(SsRainsG) },
        { "FORTIS_CARTER_G", typeof(FortisCarterG) },
        { "FORTIS_CARTER_B", typeof(FortisCarterB) },
        { "KNIGHT_COLLIN_B", typeof(KnightCollinB) },
        { "KNIGHT_COLLIN_G", typeof(KnightCollinG) },
        { "FORTIS_ZELLER_G", typeof(FortisZellerG) },
        { "FORTIS_ZELLER_S", typeof(FortisZellerS) },
        { "KNIGHT_FORGE_G", typeof(KnightForgeG) },
        { "KNIGHT_FORGE_B", typeof(KnightForgeB) },
        { "FLOWER_MERLIN_G", typeof(FlowerMerlinG) },
        { "FLOWER_MERLIN_B", typeof(FlowerMerlinB) },
        { "FLOWER_MERLIN_S", typeof(FlowerMerlinS) },
        { "VALENTINE_SS_G", typeof(ValentineSsG) },
        { "VALENTINE_SS_B", typeof(ValentineSsB) },
        { "METAL_ZC_G", typeof(MetalZcG) },
        { "METAL_ZC_S", typeof(MetalZcS) },
        { "SCI_RAINS_G", typeof(SciRainsG) },
        { "SCI_RAINS_B", typeof(SciRainsB) },
        { "SCI_RAINS_S", typeof(SciRainsS) },
        { "BALLAD_TYPHOON_A", typeof(BalladTyphoonA) },
        { "BALLAD_TYPHOON_B", typeof(BalladTyphoonB) },
        { "BALLAD_TYPHOON_G", typeof(BalladTyphoonG) },
        { "BALLAD_TYPHOON_S", typeof(BalladTyphoonS) },
        { "OCCULTISM_T_G", typeof(OccultismTripleG) },
        { "OCCULTISM_T_S", typeof(OccultismTripleS) },
        { "CHIVALRY_FC_G", typeof(ChivalryFcG) },
        { "CHIVALRY_FC_B", typeof(ChivalryFcB) },
        { "CHIVALRY_FC_S", typeof(ChivalryFcS) },
        { "WAITER_COLLIN_G", typeof(WaiterCollinG) },
        { "WAITER_COLLIN_B", typeof(WaiterCollinB) },
        { "JAM_RZ_A", typeof(JamRzA) },
        { "JAM_RZ_B", typeof(JamRzB) },
        { "JAM_RZ_G", typeof(JamRzG) },
        { "SWORD_COLLIN_A", typeof(SwordCollinA) },
        { "SWORD_COLLIN_G", typeof(SwordCollinG) },
        { "SWORD_COLLIN_B", typeof(SwordCollinB) },
        { "SWORD_COLLIN_S", typeof(SwordCollinS) },
        { "SWORD_RAINS_G", typeof(SwordRainsG) },
        { "SWORD_RAINS_B", typeof(SwordRainsB) },
        { "ONSEN_TYPHOON_G", typeof(OnsenTyphoonG) },
        { "ONSEN_TYPHOON_BE", typeof(OnsenTyphoonBe) },
        { "ONSEN_TYPHOON_BT", typeof(OnsenTyphoonBt) },
        { "ONSEN_TYPHOON_S", typeof(OnsenTyphoonS) },
        { "ONSEN_SETH_B", typeof(OnsenSethB) },
        { "ONSEN_SETH_S", typeof(OnsenSethS) },
        { "ONSEN_STAR_G", typeof(OnsenStarG) },
        { "ONSEN_STAR_B", typeof(OnsenStarB) },
        { "ONSEN_STAR_S", typeof(OnsenStarS) },
        { "ONSEN_RAINS_A", typeof(OnsenRainsA) },
        { "ONSEN_RAINS_G", typeof(OnsenRainsG) },
        { "ONSEN_RAINS_B", typeof(OnsenRainsB) },
        { "ALLEGORY_TP_A", typeof(AllegoryTpA) },
        { "ALLEGORY_TP_G", typeof(AllegoryTpG) },
        { "ALLEGORY_TP_S", typeof(AllegoryTpS) },
        { "ALLEGORY_SETH_G", typeof(AllegorySethG) },
        { "ALLEGORY_SETH_B", typeof(AllegorySethB) },
        { "ALLEGORY_SETH_S", typeof(AllegorySethS) },
        { "HALLOWEEN_ELLIS_GS", typeof(HalloweenEllisGs) },
        { "HALLOWEEN_ELLIS_GT", typeof(HalloweenEllisGt) },
        { "HALLOWEEN_ELLIS_B", typeof(HalloweenEllisB) },
        { "HALLOWEEN_ELLIS_S", typeof(HalloweenEllisS) },
    };

    /// <summary>
    /// 注册buff，必须继承自BaseBuff，重复注册将覆盖
    /// </summary>
    /// <param name="buffId"></param>
    /// <param name="buffType"></param>
    public static void RegisterBuff(string buffId, Type buffType)
    {
        if (buffType.IsSubclassOf(typeof(BaseBuff)) || buffType == typeof(BaseBuff))
        {
            BuffTypeDict.TryAdd(buffId, buffType);
        }
    }

    public static BaseBuff CreateBuff(string buffId)
    {
        if (BuffTypeDict.TryGetValue(buffId, out var type))
            return Activator.CreateInstance(type) as BaseBuff;
        GD.PrintErr($"无法找到Buff, ID:{buffId}");
        return null;
    }
}